

// Day6手写： 
// 1.算法题：https://leetcode-cn.com/problems/max-chunks-to-make-sorted-ii/


// 2.手写题：https://bigfrontend.dev/zh/problem/implement-your-own-URLSearchParams
class MyURLSearchParams {
    /**
     * @params {string} init
     */
    constructor(init) {
      init = init.replace('?','')
      let arr = init.split('&')
      this.params=arr.map(e=>{
        let [key,value]= e.split('=')
        return {key,value}
      })
      
    }
    
    /** 
     * @params {string} name
     * @params {any} value
     */
    append(name, value) {
      this.params.push({'key':name,'value':value})
    }
    
    /**
     * @params {string} name
     */
    delete(name) {
      
    }
    
    /**
     * @returns {Iterator} 
     */
    entries() {
      
    }
    
    /**
     * @param {(value, key) => void} callback
     */
    forEach(callback) {
      
    }
    
    /**
     * @param {string} name
     * returns the first value of the name
     */
    get(name) {
     return this.params.find(e=> { 
        return e.key==name
       })
    }
    
    /**
     * @param {string} name
     * @return {string[]}
     * returns the value list of the name
     */
    getAll(name) {
      return this.params.filter(e=>{
        if(e.key==name){
           return e
        }
        
      })
    }
    
    /**
     * @params {string} name
     * @return {boolean}
     */
    has(name) {
      return this.params.some(e=>{
        return e.key == name
      })
    }
    
    /**
     * @return {Iterator}
     */
    keys() {
      return this.params.map(e=>{
        return e.key
      })
    }
    
    /**
     * @param {string} name
     * @param {any} value
     */
    set(name, value) {
      this.params.forEach(e=>{
        if(e.key == name){
          e.value=value
        }
      })
    }
    
    // sor all key/value pairs based on the keys
    sort() {
      return this.params
    }
    
    /**
     * @return {string}
     */
    toString() {
      return JSON.stringify(this.params)
    }
    
    /**
     * @return {Iterator} values
     */
    values() {
    return this.params.map(e=>e.value)
    }
  }